<template>
	<view id="page">
		<nav-bar :navH="navH" :isTabar="false" :isHome="false" :pageName="title"></nav-bar>
		<view class="banner">
			<image :src="detail.icon" mode="widthFix" lazy-load="true"></image>
			<view class="colls">
				<text class="t">{{detail.topic_name}}</text>
				<text class="c">{{detail.content}}</text>
			</view>
		</view>
		<!-- 图文列表 -->
	    <view class="classify clearfloat">
			<view :class="['class-i', isOn === 0 ? 'on' : '']" @click='switchMenu(0)'>全部</view>
			<view :class="['class-i', isOn === 1 ? 'on' : '']" @click='switchMenu(1)'>视频({{spnum}})</view>
			<view :class="['class-i', isOn === 2 ? 'on' : '']" @click='switchMenu(2)'>图文({{zxnum}})</view>
	    </view>
		<!-- 图文列表 -->
		<!-- <pic-txt :lists="lists" v-if="hasRes"></pic-txt>
		<view class="nocont" v-else>暂无内容</view> -->
		<view class="nomore" v-if="isLoad"><image src='../../static/nomore_img.png' mode="widthFix"></image><text>没有更多了~</text></view>
		<scope-box :isLogin="isLogin" @isShow="isShow"></scope-box>
	</view>
</template>

<script>
	// import PicTxt from '../../components/pictxt/index.vue'
	import app from '../../common/index.js'
	export default {
		data() {
			return {
				title: '话题',
				navH: null,
				userInfo: {},
				isLogin: false,
				htId: '',  // 话题ID
				detail: {},
				spnum: 5,
				zxnum: 6,
				isOn: 0,
				hasRes: true,
				isLoad: true,
				page: 1,
				size: 10,
				handedData: [[],[],[]],  // 分类过的数据
				lists: [],
			}
		},
		onLoad(options) {
			this.navH = this.$store.state.navHeight;
			this.htId = options.id;
			// 获取本地用户信息
			this.userInfo = uni.getStorageSync('uinfo');
			if(!this.userInfo.id) {
				this.isLogin = true;
			}
			this.getDetail();
			this.getPicTxt();
		},
		// 下拉刷新
		onPullDownRefresh() {
			this.page = 1;
			this.lists = [];
			this.handedData = [[],[],[]];
			// 获取本地用户信息
			this.userInfo = uni.getStorageSync('uinfo');
			this.getDetail();
			this.getPicTxt();
			uni.stopPullDownRefresh();
		},
		// 上划加载
		onReachBottom() {
			if(!this.isLoad) {
				this.page = this.page + 1;
				this.getPicTxt();
			}
		},
		// 分享转发
		onShareAppMessage() {
			return {
				title: this.detail.title,
				path: 'pages/topic/index?id='+ this.htId,
			}
		},
		components: {
			// PicTxt,
		},
		methods: {
			/**
			 * @des 登录提示框
			 */
			isShow() {
				this.isLogin = false;
			},
			/**
			 * @des 获取话题详情
			 */
			getDetail() {
				app.request({
					url: 'entry/wxapp/TopicDetail',
					data: {id: this.htId}
				}, (ret) => {
					console.log(ret);
					let d = ret.data;
					this.detail = d;
				})
			},
			/**
			 * @des 获取图文列表
			 */
			getPicTxt() {
				app.request({
					url: 'entry/wxapp/TopicDetailList',
					data: {
						id: this.typeId,
						user_id: this.userInfo.id,
					}
				}, (ret) => {
					let d = ret.data.data, totalArr = this.handedData, len = d.zx_list.length;
					this.zxnum = d.zx_num; this.spnum = d.video_num;
					if (d.total > 0) {
						this.hasRes = true;
						this.isLoad = len < this.size ? true : false;
						d.zx_list.forEach((item, index) => {  // 此处做数据分类处理
							totalArr[0].push(item);
							if(item.is_video === '1') {
								totalArr[1].push(item);
							}else if(item.is_video === '0') {
								totalArr[2].push(item);
							}
						})
						this.handedData = totalArr;
						this.switchMenu(this.isOn);
					} else {
						this.hasRes = false;
					}
				})
			},
			/**
			 * @des 切换菜单
			 */
			switchMenu(i) {
				this.isOn = i;
				this.lists = this.handedData[i];
			}
		}
	}
</script>

<style>
	/** 图文分类菜单 */
	.classify {width: 100%; padding: 0 20upx; background-color: #fff;}
	.classify .class-i {float: left; margin: 0 20upx; padding: 20upx 10upx; line-height: 1; font-size: 30rpx; color: #888;}
	.classify .class-i.on {color: #82d7d0; border-bottom: 2px solid #82d7d0;}
	
	.banner {position: relative; max-height: 400upx; overflow: hidden;}
	.banner .colls {position: absolute; width: 100%; top: 0; bottom: 0; padding: 30upx; background-color: rgba(0,0,0,.5);}
	.banner .colls text {display: block; color: #fff; text-align: left;}
	.banner .colls .t {margin-top: 20%; font-size: 40upx; font-weight: bold;}
	.banner .colls .c {margin-top: 15upx; font-size: 30upx;}
</style>
